/**
 * ...
 * @author Yog
 */

package com.yff.listeners;

import js.Dom;

class DomListener
{
  public dynamic static function add(el : Dynamic, t : String, f : Event -> Void)
  {
	  //trace("add");
    (
      add = untyped if (window.addEventListener)
      {
		//  trace("window.addEventListener");
        function(el, t, f)
        {
          el.addEventListener(t, f, false);
        };
      } else if (window.attachEvent) {
		  //trace("window.attachEvent");
        function(el, t, f)
        {
          el.attachEvent('on' + t, f);
        };
      } else { throw "UnsupportedBrowser"; }
    )(el, t, f);
  }

  public dynamic static function remove(el : Dynamic, t : String, f : Event -> Void)
  {
    (
      remove = untyped if (window.removeEventListener)
      {
        function(el, t, f)
        {
          el.removeEventListener(t, f, false);
        };
      } else if (window.detachEvent) {
        function(el, t, f)
        {
          el.detachEvent('on' + t, f);
        };
      } else { throw "UnsupportedBrowser"; }
    )(el, t, f);
  }
}